Texture2D ShaderTexture;
SamplerState SampleType;

cbuffer LightBuffer
{
	float4 ambientColor;
	float4 diffuseColor;
	float3 lightDirection;
	float specularPower;
	float4 specularColor;
};

struct PixelInputType
{
	float4 position : POSITION;
	float2 tex : TEXCOORD0;
	float3 normal : NORMAL;
	float3 viewDirection : TEXCOORD1;
};

float4 LightPixelShader(PixelInputType input) : SV_TARGET
{
	float4 textureColor;
	float3 lightDir;
	float lightIntensity;
	float4 color;
	float3 reflection;
	float4 specular;

	textureColor = ShaderTexture.Sample(SampleType, input.tex);

	color = ambientColor;

	specular = float4(0.0f, 0.0f, 0.0f, 0.0f);

	lightDir = -lightDirection;

	lightIntensity = saturate(dot(input.normal, lightDir));

	if(lightIntensity > 0.0f)
	{
		color += (diffuseColor * lightIntensity);

		color = saturate(color);

		reflection = normalize(2 * lightIntensity * input.normal - lightDirection);

		specular = pow(saturate(dot(reflection, input.viewDirection)), specularPower);
	}

	//color = saturate(color);

	color = color * textureColor;

	color = saturate(color + specular);

	return color;
}